<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Menu
{
	function setVars()
	{
        
		$this->menu = array(
			'1' => anchor('news', 'News'),
            '2' => anchor('billboard', 'Billboard'),
			'4' => anchor('ticket', 'Support'),
			'5' => anchor('test', 'Test'),
			);
        
        if($this->uid > 0){
            $this->menu['3'] = anchor('contact/person', 'Profile');
            $this->sub['contact'] = array(
                anchor('contact/person','User'),
                anchor('contact/company','Comapny'),
                anchor('contact/secquestion','Security'),
                anchor('contact/password','Password')
                );
		}

        if($this->uid == 1){
            $this->menu['100'] = anchor('admin/', 'Admin');
            $this->sub['admin'] = array(
                anchor('admin/data','Nested Data'),
                anchor('admin/pages','DB Pages'),
                anchor('admin/pages/add_edit_page','DB Page Add'),
                );
		}
        
		$this->sub['news'] = array(anchor('news/post','Post'));
		$this->sub['ticket'] = array(anchor('ticket/newTicket','New'));

        $this->sub['billboard'] = array(
            anchor('billboard/bb_vehicle','Vehicle List'),
            anchor('billboard/bb_vehicle/add','Vehicle Add'),
            anchor('billboard/vehicle/vehicle_list','Vehicle List'),
            anchor('billboard/vehicle/vehicle_add_edit','Vehicle Add'),
            );
		
        $this->sub['test'] = array(anchor('test/sess','Sessions'));
	}
	
	function Menu()
	{
		log_message('debug', 'Menu: initialized');
	}
	
	function mkMenu()
	{
		$CI =& get_instance();
        $this->uid = $CI->session->userdata('uid');
		$this->setVars();
		ksort($this->menu);
		$segment = $CI->uri->segment(1);
		foreach($this->menu as $k => $v){
			$menutmp[$k] = $v;
			if (strripos($v, $segment) !== FALSE && isset($this->sub[$segment])){
				$this->menu[$this->menu[$k]] = $this->sub[$segment];
				unset($menutmp[$k]);
				$menutmp[$this->menu[$k]] = $this->sub[$segment];
			}
		}
		return $menutmp;
	}
}
?>
